home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Programming / MuManual / Include / mmu / exceptions.h < prev    next >
C/C++ Source or Header  |  2000-04-02  |  11KB  |  289 lines

  1. /*************************************************************************
  2.  ** mmu.library                                                         **
  3.  **                                                                     **
  4.  ** a system library for arbitration and control of the MC68K MMUs      **
  5.  **                                                                     **
  6.  ** © 1998 THOR-Software, Thomas Richter                                **
  7.  ** No commercial use, reassembly, modification without prior, written  **
  8.  ** permission of the authors.                                          **
  9.  ** Including this library in any commercial software REQUIRES a        **
  10.  ** written permission and the payment of a small fee.                  **
  11.  **                                                                     **
  12.  **---------------------------------------------------------------------**
  13.  ** exception related definitions                                       **
  14.  **                                    **
  15.  ** $VER: 40.50 (31.10.99)                        **
  16.  *************************************************************************/
  17.  
  18. #ifndef MMU_EXCEPTIONS_H
  19. #define MMU_EXCEPTIONS_H
  20.  
  21. #ifndef EXEC_TYPES_H
  22. #include <exec/types.h>
  23. #endif
  24.  
  25. #ifndef EXEC_PORTS_H
  26. #include <exec/ports.h>
  27. #endif
  28.  
  29. #ifndef EXEC_INTERRUPTS_H
  30. #include <exec/interrupts.h>
  31. #endif
  32.  
  33.  
  34. /* The exception data structure. This structure is passed in register a0
  35.    for exception hooks and is the one and only information source about
  36.    the exception. This structure will be deleted as soon as the exception
  37.    terminates, hence make a copy for private use if you need to pass it
  38.    over to someone else.
  39.  */
  40.  
  41. struct ExceptionData {
  42.         struct  Task            *exd_Task;
  43. /* The task that caused the exception. Meaningless if this is the exception
  44.    handler of the (a) supervisor context. */
  45.  
  46.         struct MMUContext       *exd_Context;
  47. /* The context this exception is part of. */
  48.  
  49.         ULONG                   *exd_Descriptor;
  50. /* The true physical hardware descriptor as seen by the MMU. In case of
  51.    an indirect descriptor, this points to the pointer, not to (your) page
  52.    descriptor itself. */
  53.  
  54.         ULONG                   *exd_NextDescriptor;
  55. /* In case of a misaligned access, i.e. an access that passes a page
  56.    boundary, the descriptor of the second page involved in the access.
  57.    Otherwise identical to exd_Descriptor */
  58.  
  59.         APTR                     exd_FaultAddress;
  60. /* The address that failed. */
  61.  
  62.         APTR                     exd_NextFaultAddress;
  63. /* This is the final end address, inclusively, of a failed access.
  64.    Note that this might well be less than "exd_FaultAddress", e.g. if the 
  65.    faulty instruction is a movem.l regs,-(ax).
  66.  
  67.    ABS(exd_FaultAdress-exd_NextFaultAddress)+1 is the size of the access
  68.    that failed. Usually 1, 2 and 4 for byte, word and longword accesses, but
  69.    other sizes are possible as well. In case you're writing a swapper daemon,
  70.    make sure you make all addresses within this range valid.
  71. */
  72.  
  73.         ULONG                    exd_UserData;
  74. /* User data for the first page in the failed access if available. This is
  75.    the block Id for swapped out pages. */
  76.  
  77.         ULONG                    exd_NextUserData;
  78. /* User data for the second page in a misaligned access. Identical to 
  79.    exd_UserData otherwise. */
  80.  
  81.         ULONG                    exd_Data;
  82. /* CPU output pipeline, right justified, if available, i.e. if the page(s)
  83.    is (are) marked as MAPP_REPAIRABLE. 
  84.    Can be modified for your code, provided you set the EXDF_READBACK flag
  85.    and the page is repairable. In this case, this data will be loaded back
  86.    to the input pipeline of the CPU. */
  87.  
  88.         APTR                     exd_ReturnPC;
  89. /* The approximate PC of the faulted instruction. Note that the real PC
  90.    might differ due to instruction prefetch. The program is guaranteed to
  91.    continue at the "right" PC, however.
  92.    In case you set the EXDF_CALL flag, this is the pointer to a routine that
  93.    will be called by the library in user mode, e.g. for posting a message
  94.    to the swapper daemon. */
  95.  
  96.         ULONG                    exd_Flags;
  97. /* A flags field, see below for the definitions. */
  98.  
  99.         UBYTE                    exd_internal;
  100. /* Do not read or write this byte. */
  101.  
  102.         ULONG                    exd_Properties;
  103. /* Properties of the accessed memory */
  104.  
  105.         ULONG                    exd_NextProperties;
  106. /*Properties of the next descriptor, if misaligned */
  107.  
  108.         UBYTE                    exd_FunctionCode;
  109. /* The function code mask of the access. */
  110.  
  111.         BYTE                     exd_Level;
  112. /* The level of the *exd_Descriptor responsible for the fault. "0" is the
  113.    level A, "1" is level B and so on. Note that this is different from how
  114.    the 680x0 MMUs count. */
  115.  
  116.         BYTE                     exd_NextLevel;
  117. /* The level of the *exd_NextDescriptor in case of a misalgined access.
  118.    Identical to exd_Level otherwise. */
  119.  
  120.         ULONG                    exd_DataRegs[8];
  121. /* A copy of the data registers of the faulty program. For higher magic,
  122.    you *might* be able to modify these. */
  123.  
  124.         ULONG                    exd_AddrRegs[7];
  125. /* A copy of the address registers, a0 to a6. a7 is below. */
  126.  
  127.         UWORD                   *exd_SSP;
  128. /* The supervisor stack pointer, points to the exception stack frame.
  129.    DO NOT touch this stack frame, this is the buisiness of the library. */
  130.  
  131.         UWORD                   *exd_USP;
  132. /* The user stack pointer. */
  133.  
  134.         struct ExecBase         *exd_SysBase;
  135. /* A cached copy of the exec.library base address. DO NOT access AbsExecBase
  136.    within an exception handler, this will be fatal. Use either a private
  137.    copy or this field. */
  138.  
  139.         struct MMUBase          *exd_MMUBase;
  140. /* The base of the mmu.library. */
  141. };
  142.  
  143. /* The flags set in exd_Flags, above. Note that there are more flags than
  144.    documented here, but DO NOT touch or interpret these. */
  145.  
  146. /* input flags    (set by the exception handler)        */
  147.  
  148.  
  149. #define EXDF_WRITE              (1<<0L)
  150. #define EXDB_WRITE              0L
  151. /* A faulty write if set. A read exception if reset.
  152.    A 060 read/modify/write access will invoke the exception handler twice.
  153.    Note that locked transfers (what is called a RMW-access on a 020 or 030) 
  154.    are neither handled by the Amiga hardware nor the mmu.library software. */ 
  155.  
  156. #define EXDF_INSTRUCTION        (1<<1L)
  157. #define EXDB_INSTRUCTION        1L
  158. /* A faulty instruction access. This means specifically that you MAY NOT
  159.    provide read-back data. You've either to stop the task, or swap in a page.
  160.    Note that EXDF_WRITE and EXDF_INSTRUCTION are possible in case a faulty
  161.    program uses a "moves" instruction with the dfc register loaded with an
  162.    instruction function code. Note, too, that the os never tries to do that
  163.    and that this method is not supported by the mmu.library. */
  164.  
  165. #define EXDF_WRITEPROTECTED     (1<<2L)
  166. #define EXDB_WRITEPROTECTED     2L
  167. /* The fault was due to a write to a write protected page. */
  168.  
  169. #define EXDF_WRITEDATAUNKNOWN   (1<<3L)
  170. #define EXDB_WRITEDATAUNKNOWN   3L
  171. /* The mmu library could not get hold of the data actually written out,
  172.    exd_Data is invalid. Set pages to MAPP_REPAIRABLE to get write data. */
  173.  
  174. #define EXDF_SUPERVISOR         (1<<6L)
  175. #define EXDB_SUPERVISOR         6L
  176. /* The fault was due to access of a supervisor only page. */
  177.  
  178. #define EXDF_MISALIGNED         (1<<8L)
  179. #define EXDB_MISALIGNED         8L
  180. /* The access spawned more than one page in memory. */
  181.  
  182.  
  183. /* The following flags are output flags. You may set them in your code and
  184.    they are respected by the library. */
  185.  
  186. #define EXDF_READBACK           (1<<16L)
  187. #define EXDB_READBACK           16L
  188. /* Fill the input pipeline of the CPU with the data in exd_Data, right
  189.    justified. */
  190.  
  191. #define EXDF_WRITECOMPLETE      (1<<16L)        /* yes, the same number */
  192. #define EXDB_WRITECOMPLETE      16L
  193. /* The exception handler was able to perform the writeback of exd_Data,
  194.    the CPU should ignore the faulty write and continue execution.
  195.    If this bit is not set, the access is retried. */
  196.  
  197. #define EXDF_CALL               (1<<17L)
  198. #define EXDB_CALL               17L
  199. /* Call a routine in user mode, the address is given in exd_ReturnPC.
  200.    The access is retried as soon as this routine returns. 
  201.    The user routine executes in user mode in the context of the task that
  202.    faulted and has full access to the multitasking machine of exec. 
  203.    (This requires really a lot of meta-magic....).
  204.    Do NOT set EXDF_WRITECOMPLETED/EXDF_READBACK and EXDF_CALL at once, only
  205.    one of the two bits should be set. */
  206.  
  207.  
  208. /* The next lines define the exception types, passed in for example to 
  209.    AddContextHook(). This type determinates to which exception hook list
  210.    your hook will be added. */
  211.  
  212. #define MMUEH_SEGFAULT          0L
  213. /* a segmentation fault, i.e. access of invalid or supervisor protected
  214.    memory, or writes to write-protected memory. */
  215.  
  216. #define MMUEH_SWAPPED           1L
  217. /* access of memory that is marked as "swapped out". */
  218.  
  219. #define MMUEH_SWITCH            0x10L
  220. /* called whenever a task looses the CPU. This is task specific and requires
  221.    that the specific task has been entered a context explicitly. This holds
  222.    even for the public default context. */
  223.  
  224. #define MMUEH_LAUNCH            0x11L
  225. /* called whenever a task gains control over the CPU. */
  226.  
  227. #define MMUEH_PAGEACCESS        0x20L
  228. /* called on installation of a MAPP_SINGLE page. */
  229.  
  230. /* The next structure is the exception handler itself. Note that this is
  231.    *NOT* the full definition. This structure is really "internal use only"
  232.    you should not read or write it. It's only documented here for complete-
  233.    ness. */
  234.  
  235. struct ExceptionHook {
  236.         struct Interrupt        exh_Interrupt;
  237.         /* more below here. */
  238. };
  239.  
  240. /* The next structure is sent to the "Catcher" port for the high-level
  241.    message hook mechanism. */
  242.  
  243. struct ExceptionMessage {
  244.         struct Message          exm_Message;
  245.         struct ExceptionData    exm_Exception;
  246. };
  247.  
  248. /* If this is replied, then the access is retried and the faulty task is
  249.    continued. */
  250.  
  251.  
  252.  
  253. /* The PageAccessData structure
  254.    this is passed to a page access handler
  255.    in register a0, with your data in a1 and a4.
  256.    This is only called for MAPP_SINGLE pages, at the
  257.    page level.
  258.    The code is called in supervisor level, with all
  259.    interrupts disabled. */
  260.  
  261. struct PageAccessData {
  262.         ULONG                    pgad_Level;
  263. /* level of the tree that is getting build */
  264.  
  265.         void                    *pgad_Address;
  266. /* the logical address this is build for */
  267.  
  268.         ULONG                   *pgad_Destination;
  269. /* where the descriptor will go to */
  270.  
  271.         struct MMUContext       *pgad_Context;
  272. /* the context this is build for */
  273.  
  274.         struct MMUBase          *pgad_MMUBase;
  275. /* The base of the mmu.library. */
  276.  
  277.         ULONG                    pgad_Properties;
  278. /* The properties for this descriptor */
  279.  
  280.         ULONG                    pgad_UserData;
  281. /* User data for the descriptor.
  282.    This is the user data for invalid/swapped pages,
  283.    the destination address for remapped pages and
  284.    the descriptor address for indirect pages. */
  285. };
  286.  
  287.  
  288. #endif
  289.